package com.itbaiyun.usercenter.controller;

import com.itbaiyun.usercenter.common.BaseResponse;
import com.itbaiyun.usercenter.common.ErrorCode;
import com.itbaiyun.usercenter.common.ResultUtil;
import com.itbaiyun.usercenter.exception.BusinessException;
import com.itbaiyun.usercenter.model.domain.User;
import com.itbaiyun.usercenter.service.UserFollowService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 用户关注接口
 */
@RestController
@RequestMapping("/follow")
public class FollowController {
    @Resource
    private UserFollowService userFollowService;

    /**
     *  关注用户
     * @param followId 要关注用户的id
     * @return 返回结果
     */
    @PostMapping("/{id}/{isFollow}")
    private BaseResponse<Boolean> followUser(@PathVariable("id") Long followId, @PathVariable("isFollow") boolean isFollow, HttpServletRequest request){
        return userFollowService.followUser(followId,isFollow,request);
    }

    /**
     *  是否已经关注
     * @param followId 被关注人id
     * @param request 关注用户
     * @return 返回结果
     */
    @GetMapping("/ornot/{id}")
    public BaseResponse<Boolean> isFollow(@PathVariable("id")Long followId,HttpServletRequest request){
        return ResultUtil.sucess(userFollowService.isFollow(followId,request));
    }

    /**
     * 查看共同关注用户信息
     * @param followId 关注人的id
     * @param request  获取登录用户
     * @return 返回结果
     */
    @PostMapping("/findCommon/{id}")
    public List<User> findCommonUser(@PathVariable("id") Long followId, HttpServletRequest request){
        List<User> userList =  userFollowService.findCommonUser(followId,request);
        return userList;
    }


}
